package com.qf.springbootitem.config;
import com.qf.springbootitem.swaggerproperties.Properties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
public class SwaggerConfig {

    @Autowired
    Properties properties;

    @Bean
    public Docket docket(){

       return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(getApiInfo())
                .select()
                //指定swagger扫描的包路径
                .apis(RequestHandlerSelectors.basePackage(properties.getBasePackage()))
                .build();
    }

    private ApiInfo getApiInfo() {

       return new ApiInfoBuilder()
               .contact(new Contact(properties.getName(),properties.getUrl(),properties.getEmail()))
               .title(properties.getTitle())
               .version(properties.getVersion())
               .description(properties.getDescription())
                .build();
    }
}
